package com.nf.db.handlers.list;

import com.nf.db.handlers.ResultSetHandler;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/*
 * 让别的子类继承此类，实现handlerRow方法，即可实现自定义的ResultSetHandler
 * */
public abstract class AbstractListHandler<T> implements ResultSetHandler<List<T>> {
    @Override
    public final List<T> handle(ResultSet rs) throws SQLException {
        List<T> result = new ArrayList<T>();
        while (rs.next()) {
            T row = handlerRow(rs);
            result.add(row);
        }
        return result;
    }

    protected abstract T handlerRow(ResultSet rs) throws SQLException;
}
